home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-01 | 5.1 KB | 191 lines | [TEXT/PJMM] |
-
- { MWMain Unit.}
- { This unit contains the event loop and the loop procedure for the MacTutor demo.}
-
- program MWMain;
-
- uses
- MeterWindow;
-
- {--------------------------------------------------------------------------------------------}
- { DoMeterWindowDemo procedure}
- { This procedure demonstrates the Meter Window interface. It uses three nested loops to}
- { create a dummy task that is slow enough to show the Meter Window functionality. This }
- { procedure accepts one parameter, runSmart. When runSmart is true, the Meter Window is}
- { displayed during the loop execution; if runSmart is false the then loop is executed but}
- { without creating the Meter Window.}
-
- procedure DoMeterWindowDemo (runSmart: boolean);
-
- const
- outLoop = 5;
- loopsize = 500;
- meterGrade = 20;
-
- var
- i, j, m, n: integer;
- myCursor: CursHandle;
- meterhit, k, innerloop: longint;
- dWorld: SysEnvRec;
- rnum: OSErr;
- vReq: integer;
- iStr: Str255;
-
- begin
- { First determine which processor is in this Mac and then adjust the innerloop parameter}
- { accordingly. This is done so that the loop will not execute too quickly on high-powered}
- { Macs.}
- vReq := 1;
- rnum := SysEnvirons(vReq, dWorld);
- if rnum = 0 then
- begin
- if dWorld.processor = env68000 then
- innerloop := loopsize
- else if dWorld.processor = env68010 then
- innerloop := loopsize
- else if dWorld.processor = env68020 then
- innerloop := 20 * loopsize
- else
- innerloop := 20 * loopsize;
- end
- else
- innerloop := loopsize;
- { Figure out how many loops equal 5% of the total loop.}
- meterHit := longint(round(loopsize / meterGrade));
-
- myCursor := GetCursor(WatchCursor);
- SetCursor(myCursor^^);
- { This is always the first call to the MeterWindow unit. It initializes and displays }
- { the Window Meter}
- if runSmart then
- mWindowInit;
-
- for n := 1 to outLoop do
- begin
- { for each of the n loops, create a new Meter Window title.}
- NumToString(n, iStr);
- iStr := concat('MacTutor Demo - Loop ', iStr);
- iStr := concat(iStr, ' of 5.');
- { Now eraes the Meter Window and redraw it with a new title.}
- if runSmart then
- begin
- mWindowDraw;
- mWindowTitle(iStr);
- end;
- m := 1;
- for i := 1 to loopsize do
- begin
- { When m = meterHit the another 5% of the total loop has been completed and it is time to}
- { update the meter box in the Meter Window.}
- if m = meterHit then
- begin
- m := 1;
- if runSmart then
- mWindowUpdate(i, loopsize);
- end
- else
- m := m + 1;
- k := 0;
- { This is the dummy innerloop that is adjusted based on the current processor.}
- for j := 1 to innerloop do
- k := k + 1;
- end;
- end;
- { All done! Now destroy the Meter Window.}
- if runSmart then
- mWindowKill;
- InitCursor;
- end;
-
- { This is the main procedure for this demo. It sets up the Apple and Meter menus and handles}
- { the selection of items from these menus.}
-
- const
- AppleID = 1;
- MeterID = 2;
- AboutItem = 1;
- RunDItem = 1;
- RunSItem = 2;
- QuitItem = 3;
-
- var
- appleMenu, meterMenu: MenuHandle;
- myTitle: string[1];
- daName: Str255;
- dEvent: EventRecord;
- TimeToQuit: boolean;
- dPart, dItem, dMenu, daNum: integer;
- dWindow: WindowPtr;
- dChoice: longint;
-
- begin
- InitCursor;
- { Set up the menus.}
- myTitle := ' ';
- myTitle[1] := CHR(appleMark);
- appleMenu := NewMenu(AppleID, myTitle);
- AddResMenu(appleMenu, 'DRVR');
- InsertMenu(appleMenu, 0);
- meterMenu := NewMenu(MeterID, 'Meter');
- AppendMenu(meterMenu, 'Run Dumb');
- AppendMenu(meterMenu, 'Run Smart');
- AppendMenu(meterMenu, 'Quit');
- InsertMenu(meterMenu, 0);
- DrawMenuBar;
-
- TimeToQuit := false;
- { The TimeToQuit variable is set to true when the Quit item is selected from the Meter menu.}
- while not TimeToQuit do
- begin
- SystemTask;
- if GetNextEvent(everyEvent, dEvent) then
- begin
- { Only handle mousedown events in this simple demo.}
- case dEvent.what of
- MouseDown:
- begin
- dPart := FindWindow(dEvent.where, dWindow);
- case dPart of
- { The SysWindow mousedown is for Desk Accessories.}
- InSysWindow:
- SystemClick(dEvent, dWindow);
- InMenuBar:
- begin
- { Figure out which menu item was selected.}
- dChoice := MenuSelect(dEvent.where);
- dItem := LoWord(dChoice);
- dMenu := HiWord(dChoice);
- case dMenu of
- AppleID:
- begin
- { If an Apple menu item was selected, then do the item.}
- GetItem(appleMenu, dItem, daName);
- daNum := OpenDeskAcc(daName);
- end;
- MeterID:
- begin
- case dItem of
- RunDItem:
- { The Run Dumb item was selected. Do the loop processing without displaying the Meter Window.}
- DoMeterWindowDemo(false);
- RunSItem:
- { Do the loop processing and display the Meter Window.}
- DoMeterWindowDemo(true);
- QuitItem:
- { Quit and go home.}
- TimeToQuit := true;
- otherwise
- end;
- end;
- otherwise
- end;
- HiliteMenu(0);
- end;
- otherwise
- end;
- end;
- otherwise
- end;
- end;
- end;
- end.